package com.xhdx.threadpool;


import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleThreadTest {

    /**
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        ScheduledExecutorService service = null;
        try {
            service = Executors.newScheduledThreadPool(4);
            final Runnable myRunable = new Runnable() {
                public void run() {
                    System.out.println(Thread.currentThread().getName());
                }
            };

            service.scheduleAtFixedRate(myRunable, 0, 1, TimeUnit.SECONDS);
            service.scheduleAtFixedRate(myRunable, 0, 1, TimeUnit.SECONDS);
            service.scheduleAtFixedRate(myRunable, 0, 1, TimeUnit.SECONDS);
            service.scheduleAtFixedRate(myRunable, 0, 1, TimeUnit.SECONDS);

            service.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
        } finally {
            if (service != null) {
                service.shutdown();
            }
        }
    }
}

